package com.sydx.service;

import com.github.pagehelper.PageHelper;
import com.sydx.dao.JobDao;
import com.sydx.entity.Course;
import com.sydx.entity.Job;
import com.sydx.utils.BeanMapUtils;
import com.sydx.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author zoutr
 * @Description
 * @Date 2021/6/29
 **/
@Service
public class JobService {

    @Autowired
    private JobDao jobDao;

    public int create(Job pi) {
        return jobDao.create(pi);
    }

    public int delete(Integer id) {
        // 原本这样写每次都要创建map,增加了耦合性，所以创建一个MapParameter工具类，直接调用
       /* HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        return clazzDao.delete(map);*/
        return jobDao.delete(MapParameter.getInstance().addId(id).getMap());
    }

    public int update(Job job) {
        Map<String,Object> map = MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(job))
                .addId(job.getId()).getMap();
        return jobDao.update(map);
    }

    public List<Job> query(Course course) {
        /*分页查询*/
        if (course != null && course.getPage() != null) {
            PageHelper.startPage(course.getPage(),course.getLimit());
        }
        return jobDao.query(BeanMapUtils.beanToMap(course));
    }

    public List<Job> query(Job job) {
        return jobDao.query(BeanMapUtils.beanToMap(job));
    }

    public Job detail(Integer id) {
        return jobDao.detail(MapParameter.getInstance().addId(id).getMap());
    }

    public Job detailByStudent(Integer stuId) {
        return jobDao.detail(MapParameter.getInstance().add("stuId",stuId).getMap());
    }

    public int count(Job job) {
        return jobDao.count(BeanMapUtils.beanToMap(job));
    }
}
